/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package commons;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 *
 * @author Leonardo Oliveira Moreira
 */
public class Constants {

    public static final String DB_DRIVER = "org.postgresql.Driver";
    public static final String DB_ADDRESS = "s";
    public static final String DB_USERNAME = "s";
    public static final String DB_PASSWORD = "s";
    public static final int DBMS_POSTGRES = 1;
    public static final int DBMS_MYSQL = 2;

    private Constants() {
    }

    public static String encrypt(String password) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            return new String(hexCodes(md.digest(password.getBytes())));
        } catch (NoSuchAlgorithmException ex) {
            
        }
        return null;
    }

    /**
     * Method used to transform a string of bytes in the format in an array of
     * hexadecimal characters
     *
     * @param text
     * @return
     */
    private static char[] hexCodes(byte[] text) {
        char[] hexOutput = new char[text.length * 2];
        String hexString;
        for (int i = 0; i < text.length; i++) {
            hexString = "00" + Integer.toHexString(text[i]);
            hexString.getChars(hexString.length() - 2, hexString.length(), hexOutput, i * 2);
        }
        return hexOutput;
    }

    public static void main(String[] args) {
        System.out.println(Constants.encrypt("windson123"));
        System.out.println(Constants.encrypt("mau123"));
    }
}